﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>淘划算 - 未来商店</title>
    <link rel="stylesheet" href="css/animate.css"/>
    <link rel="stylesheet" href="css/font-awesome.min.css"/>
    <link rel="stylesheet" href="css/flexslider.css"/>
    <link rel="stylesheet" href="css/base.css?20150803"/>
    <style type="text/css">
        .ms-controller, [ms-controller] {
            display: none;
        }
    </style>
</head>
<body ms-controller="idxproduct">

<!-- header 顶部 -->
<header>
    <a href="index.html" style="padding-left:10px;"><img src="images/e-jialogo.png" alt="" style="width:500px;height:70px;"/></a>
    <span class="right">
           <input type="text" class="headInput" id="keyinput" placeholder="输入商品名称"/><input type="button" class="headBtn" id="btnsearch" value="搜索"/>
    </span>
</header>

<!-- menu 菜单 -->
<menu id="category" >
    <li ms-repeat-el="ctgData" ><a ms-href="index_item.html?cat1={{el.ID}}&catn1={{el.MenuTxt}}" data-transition="slide">{{el.MenuTxt}}</a></li>
    <li id="loc1" style="display:none;"><a href="javascript:void(0);">返回首页</a></li>
    <li id="loc2" style="display:none;"><a href="javascript:void(0);" >本地商品</a></li>
   
</menu>

<!-- slider 轮播图片 -->
<div class="flexslider">
    <ul class="slides" >
        <li ms-repeat-el="ctsData">
           <a ms-href="shopDetail.html?id={{el.Details}}"><img ms-src="{{el.ImgUrl}}" /></a> 
        </li>
    </ul>
</div>


<!-- 商品列表 促销打折 -->
<div class="goodList">
    <!--<div class="title">
        <img src="./images/icon1.jpg" />促销打折 <a href="javascript:;" class="more">更多</a>
    </div>-->
    <ul>
         <li ms-repeat-el="ctData" class="goodItem"><a ms-href="shopDetail.html?id={{el.ID}}"><img ms-src="{{el.ImgUrl1}}" /><p><span>{{el.Title}}</span><b>￥{{el.Price2}}</b><del>原价：￥{{el.Price1}}</del></p></a></li>
    </ul>
</div>

<p style="text-align:center" class="loaddmore">---往下滑更精彩---</p>


<script src="js/jquery.min.js"></script>
<script src="js/jquery.flexslider-min.js"></script>
<script src="js/avalon.mobile.min.js"></script>
<script src="js/MobileCom.js"></script>
<script>
    var model = avalon.define({
        $id: "idxproduct",
        ctData: [],
        ctgData: [],
        ctsData: []
    });

    var loc = window.localStorage.getItem("loc");
    window.localStorage.removeItem("page");
    window.localStorage.setItem("page", 1);
    $(document).ready(function () {
        if (window.localStorage.getItem("EUser") == null) {
            window.location = "login.html";
        }

        //if (loc == null || loc == 1) {  //官方商品
        //    $("#loc1").css("display", "none");
        //    $("#loc2").css("display", "block");
        //} else {  //本地商品
        //    $("#loc1").css("display", "block");
        //    $("#loc2").css("display", "none");
        //}


        if (loc != null) {
            $("#liloc").css("display", "none");
        }

        $.getJSON("/View/SpeList/DLLAjaxHandler.ashx?action=GetLeiBie", function (r) {
            model.ctgData = r;
        })


        var url_gg = "/View/SpeList/DLLAjaxHandler.ashx?action=GetGG&LeiBie=首页广告";
        if (loc != null) {
            url_gg += "&euser=" + window.localStorage.getItem("EUser");
        }
        $.getJSON(url_gg, function (r) {
            model.ctsData = r;

            $(".flexslider").flexslider({
                slideshowSpeed: 4000, //展示时间间隔ms
                animationSpeed: 400, //滚动时间ms
                touch: true //是否支持触屏滑动
            });

        })


       
        loadMore();
        

        $("#loc1 a").click(function () {
            window.localStorage.removeItem("loc");
            window.localStorage.setItem("loc", "1");

            window.location = "index.html";
        })
        $("#loc2 a").click(function () {
            window.localStorage.removeItem("loc");
            window.localStorage.setItem("loc", "2");

            window.location = "index.html";
        })

        $("#btnsearch").click(function () {
            window.location = "search.html?key=" + $("#keyinput").val();
        })
        $("#keyinput").keydown(function (e) {

            if (e.keyCode == 13) {
                window.location = "search.html?key=" + $("#keyinput").val();
            }
        })

        $(window).scroll(function () {

            if ($(document).height() - $(this).scrollTop() - $(this).height() < 5) {
                loadMore();
            }

        })

    })

    var isjz = 0;

    function loadMore() {
        if (isjz == 0) {
            isjz = 1;
            var page = parseInt(window.localStorage.getItem("page"));
            if (page > 0) {
                var url = "/View/SpeList/DLLAjaxHandler.ashx?action=GetTJ&Page=" + page;
                if (loc != null && loc == 2) {
                    url += "&euser=" + window.localStorage.getItem("EUser");
                }

                $.getJSON(url, function (r) {
                    if (r.length > 0) {
                        model.ctData.pushArray(r);

                        var nxt = page + 1;
                        window.localStorage.setItem("page", nxt);



                    } else {
                        window.localStorage.setItem("page", 0);
                        $(".loaddmore").css("display", "none");
                    }
                    isjz = 0;
                })
            }
        }

    }

</script>
</body>
</html>